package com.meitianhui.convenitenbuy.module.home.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.reflect.TypeToken;
import com.meitianhui.convenitenbuy.R;
import com.meitianhui.convenitenbuy.module.home.model.bean.RecommendGoods;
import com.meitianhui.convenitenbuy.util.GlideUtils;
import com.meitianhui.convenitenbuy.util.GsonParserUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/2.
 * 限时秒杀和新品预告下面的推荐商品列表
 */

public class HomeItemReGoodsAdapter extends BaseQuickAdapter<RecommendGoods.Stores,BaseViewHolder>{
    private Context context;
    private Map<String, String> docUrl;
    public HomeItemReGoodsAdapter(Context context,List data, Map<String, String> docUrl) {
        super(R.layout.item_home_recommend_goods_item, data);
        this.context = context;
        this.docUrl  = docUrl;
    }


    @Override
    protected void convert(BaseViewHolder helper, RecommendGoods.Stores item) {
        TextView tvGoodCostPrice = helper.getView(R.id.tv_good_cost_price);
        ImageView ivGood = helper.getView(R.id.iv_good);
        helper.setText(R.id.tv_good_name,item.getTitle());
        helper.setText(R.id.tv_good_price,"¥"+item.getDiscount_price());
        tvGoodCostPrice.setText("¥"+item.getMarket_price());
        tvGoodCostPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        TypeToken<List<RecommendGoods.Stores.PicInfo>> typeToken = new TypeToken<List<RecommendGoods.Stores.PicInfo>>() {
        };
        try {
            List<RecommendGoods.Stores.PicInfo> picInfo = GsonParserUtils.getInstance().fromJson(item.getPic_info(), typeToken);
            if (picInfo != null) {
                GlideUtils.setRectImage(context,docUrl.get(picInfo.get(0).getPath_id()),R.mipmap.icon_default_picture_store,R.mipmap.icon_default_picture_store,ivGood);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
